#ifndef TEST_H
#define TEST_H

#include "qcustomplot.h"
#include "ttkgrabitemwidget.h"

class QMouseEvent;
class QRubberBand;
class CustomPlotWidget : public QCustomPlot {
    Q_OBJECT

    enum class Direction
    {
        No = 0,
        Left = 1,
        Top = 2,
        Right = 4,
        Bottom = 8,
        LeftTop = Direction::Left | Direction::Top,
        LeftBottom = Direction::Left | Direction::Bottom,
        RightTop = Direction::Right | Direction::Top,
        RightBottom = Direction::Right | Direction::Bottom
    };
public:
    CustomPlotWidget(QWidget *parent = nullptr);

    void SetupPixmapItem(QPixmap &pixmap);

protected:
    void mousePressEvent(QMouseEvent *event) override;

    void mouseMoveEvent(QMouseEvent *event) override;

    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    QPoint mSelectionStart;
    QRubberBand *rubberBand;

    //Pixmap 移动控制
    bool mDragging = false;
    QCPItemPixmap *mCurrentPixmap;
    QCPItemPixmap *pixmapItem;
    QPointF mDragStartPos;
    QPointF mOriginalTopLeft, mOriginalBottomRight;

    //放大框控制
    QCPItemRect *mRectItem = nullptr; // 动态选框图形项
    QPointF mStartPos;           // 选框起始坐标（像素）
    bool mIsSelecting = false;   // 是否正在框选

    //Pixmap 放大缩小控制
    bool m_dragging = false;
    bool m_resizing = false;
    QPointF m_dragStartPos;
    QPointF m_originalTopLeft;
    QPointF m_originalBottomRight;

    Direction m_direction;
};

#endif // TEST_H
